 
 var picture;
 var widthset=0;
 var heightset=0;
 var owidthset=0;
 var oheightset=0;
 var indexset=0;
 var imgmidset=0;
 var linkto='';
 var productidset=0;
 var tempidset=0;
 var croppicContainerModalOptions = {
                uploadUrl:'/ajax/iuploaddata',
                cropUrl:'/ajax/cropuploaddata',
                modal:false,
                imgEyecandy:false,
                onAfterImgUpload:function(){
                
                         
                 //     $('#d-'+this.objW+'x'+this.objH+'-'+this.id.split('-').pop().toLowerCase()+'').draggable();
                
                
                },
                onBeforeImgCrop:function(){ 
                
                          
                          
                          this.options.cropData={imgmid:this.imgmid,productid:productidset,owidth:this.objW,oheight:this.objH,tempid:tempidset,index:this.id.split('-').pop().toLowerCase()};
                           
                
                
                },
                loaderHtml:'<div class="loader bubblingG"><span id="bubblingG_1"></span><span id="bubblingG_2"></span><span id="bubblingG_3"></span></div> '
        }

 function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
    }
    return "";
} 
function sharefunction(index,productid,link)
{
//console.log(index);
//console.log(productid);
var linkdata='/post/'+productid;


var iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false );
var newlink = document.createElement('a');

switch(index)
{

case 0:
   if(iOS)
   {
   
   window.location='http://www.facebook.com/sharer/sharer.php?v=4&src=bm&u='+linkdata,'Facebook','height=450,width=550';
   
   
   
   
   }else
   {
   
   window.open('http://www.facebook.com/sharer/sharer.php?v=4&src=bm&u='+linkdata,'Facebook','height=450,width=550').focus() ;
   }
 // window.open('/plans/individual/continue-to-ap-pop.asp','Continue_to_Application','width=200,height=400');
  
  break;
case 1:
  window.open('http://twitter.com/intent/tweet?source=webclient&text='+linkdata,'Twitter','height=450,width=550').focus() ;
  break;
case 2:
  window.open('https://plus.google.com/share?url='+linkdata,'Google +','height=450,width=550').focus() ;
  break;
  
  
case 3:
  
  $("#txtbroadcast").val(linkdata);
 // $(".ovlPopLd").fadeOut();
  openbroadcasting();
  break;
case 4:
console.log("test 4");
   //$(".ovlPopLd").fadeOut();
  $(".wrpPopEmbed").fadeIn();
  $(".wrpPopEmbed .frmTxtArea.frmGen").val(linkdata+'/embed');
  break;
case 5:

   //$(".ovlPopLd").fadeOut();
  $(".wrpPopQRCode").fadeIn();
  $(".wrpPopQRCode .wrpFrmGen").html('<img src="http://chart.apis.google.com/chart?chs=400x400&amp;cht=qr&amp;chld=|1&chl='+encodeURIComponent(linkdata)+'" alt="QR Code" />');
  break;

}


$.post('/ajax/statdatashareweb', { productid:productid,caseid:index }, function(data) { 


});



}
$(function() {

$('.ir.button.white').click(function() {
     setcolor('white');
    $('body').removeClass('black');
    $('body').addClass('white');
    
    $('#topic').removeClass('data');
    $('#topic').removeClass('data2');
    $('#topic').addClass('data2');

    $('#detail').removeClass('data');
    $('#detail').removeClass('data2');
    $('#detail').addClass('data2');


    $('#timework').removeClass('data');
    $('#timework').removeClass('data2');
    $('#timework').addClass('data2');
    
    
    $('#contact').removeClass('data');
    $('#contact').removeClass('data2');
    $('#contact').addClass('data2');
    
    
    return false;
})
$('a.button.black').click(function() { 
    $('body').removeClass('white');
    $('body').addClass('black');
    setcolor('black');
    $('#topic').removeClass('data');
    $('#topic').removeClass('data2');
    $('#topic').addClass('data');

    $('#detail').removeClass('data');
    $('#detail').removeClass('data2');
    $('#detail').addClass('data');


    $('#timework').removeClass('data');
    $('#timework').removeClass('data2');
    $('#timework').addClass('data');
    
    
    $('#contact').removeClass('data');
    $('#contact').removeClass('data2');
    $('#contact').addClass('data');
    
    
    return false;
})
$('#login').hide();

var path=$(location).attr('pathname');  
picture = $('#sample_picture');  
// $('#rotate_left').click(function(){ picture.guillotine('rotateLeft'); });
// $('#rotate_right').click(function(){ picture.guillotine('rotateRight'); });
// $('#fit').click(function(){ picture.guillotine('fit'); });
// $('#zoom_in').click(function(){ picture.guillotine('zoomIn'); });
// $('#zoom_out').click(function(){ picture.guillotine('zoomOut'); });


function setcolor(color)
{

$.post( "/ajax/setcolordata",{productid:productidset,color:color}, function( data ) { 


});

}

function seteventimage(width,height)
{
//indexset=$('.d-'+width+'x'+height+'').index();

var dataarray=$('.d-'+width+'x'+height+'').get();

$.each(dataarray, function( index, value ) {

var indexnow=index;
//console.log('width='+width);
//console.log('height='+height);
//console.log('indexnow='+indexnow);
var idset='d-'+width+'x'+height+'-'+indexnow;
$(value).attr('id',idset);
var cropContainerModal = new Croppic(idset, croppicContainerModalOptions);
});

//var idset='d-'+width+'x'+height+'-'.indexset
//$('.d-'+width+'x'+height+'').parent().attr('id',idset);

        

       // $('.d-'+width+'x'+height+'').append('<div class="wrpUlFile" style="display:none"></div>');
   /*     $('.d-'+width+'x'+height+'').iuploader({
         'link':'/ajax/iupload',
         'accept':'image/*',
         'group':1,

         'type':['jpg', 'jpeg', 'png', 'gif'],
         'onStartUpload':function(setting)
         {
         
              $.blockUI();
         
         },
         'onUploadFinish':function(filename,filelink,setting){
              //console.log(setting);
              imgmidset=setting['imgmid']; 
              owidthset=setting['originalwidth'];
              oheightset=setting['originalheight'];
              linkto=filelink;
              picture.attr('src',filelink+'?t=1');
              picture.on('load', function(){
              picture.guillotine({eventOnChange: 'guillotinechange',width:width,height:height});
              picture.on('guillotinechange', function(ev, data, action) {
                //for(var k in data) { $('#'+k).html(data[k]); } 
                
                    
              });
              $.unblockUI();
              
              $('#popUpGen').fadeIn(); 
              });
              
              
         //alert(filename);
         }
   });
        $('.d-'+width+'x'+height+' a.ir.edit.img').click(function() {
           widthset=width;
           heightset=height;
           indexset=$(this).parent().index();
           $(this).parent().find('input[name="filedata[]"]').trigger("click");
        });
           */
}

var productid = path.split('/').pop().toLowerCase();
productidset = productid; 
$('.ir.edit.img').hide();
$('.ir.edit.text').hide();
// Handler for .ready() called.
$.get( "/ajax/getproduct",{productid:productid}, function( data ) {

                 var productdata=data.data[0];
                 var datatext='data2';
                 if(productdata.plugins[0].color==''||productdata.plugins[0].color=='black')
                 {
                        datatext='data';
                        $('body').removeClass('white');
                        $('body').addClass('black');
                        
                 }else
                 {
                 
                        $('body').removeClass('black');
                        $('body').addClass('white');
                 
                 }
                 $('#topic').removeClass('data');
                 $('#topic').addClass(datatext);
                 
                 $('#topic').html('<p>'+productdata.title+'</p>');
                 $('title').html(productdata.title);
                 $('#detail').removeClass('data');
                 $('#detail').addClass(datatext);  
                 $('#detail').html('<p>'+productdata.description+'</p>');
                 $('meta[name=description]').attr('content',productdata.description); 
                 $('#timework').removeClass('data');
                 $('#timework').addClass(datatext); 
                 if(productdata.plugins[0].alltime=='0')
                 {
                 if(productdata.plugins[0].openhours!='')
                 {
                   $('#timework').html('<p> Day :'+productdata.plugins[0].infomation+' <br> Time :'+productdata.plugins[0].openhours+'-'+productdata.plugins[0].closehours+'</p>');
                 }else
                 {
                   $('#timework').html('<p> Day :'+productdata.plugins[0].infomation+' <br> Time :</p>'); 
                 
                 }
                 
                 }
                 else
                 {
                  $('#timework').html('<p> Day :'+productdata.plugins[0].infomation+' <br> Time :24 Hours</p>');
                 }
                 $('#contact').removeClass('data');
                 $('#contact').addClass(datatext);
                  var address='';
                        address+='Address : '+productdata.plugins[0].address+' '+productdata.plugins[0].disname+','+productdata.plugins[0].tumname+' <br>';
                        address+=productdata.plugins[0].proname+' <br>';
                        address+='Tel: '+productdata.plugins[0].phone+' <br>';
                        address+='Email: '+productdata.plugins[0].email+' <br>';
                        address+='Website: '+productdata.plugins[0].website+' <br>';
                        
                        if(productdata.plugins[0].website!='')
                        {
                         var website=productdata.plugins[0].website;
                        if(productdata.plugins[0].website.indexOf("http")==-1)
                        {
                            website="http://"+productdata.plugins[0].website;

                        }
                        
                        $('#btnfav').attr('href',website);
                        
                        $('#btnfav').attr('target',"_blank");
                        
                        }
                        
                        tempidset=productdata.plugins[0].tempid;
              if(productdata.plugins[0].lng)
              {   
                //console.log(productdata.plugins[0].lng);

            
            
            
            var myLatlng = new google.maps.LatLng(parseFloat(productdata.plugins[0].lat),parseFloat(productdata.plugins[0].lng));
var mapOptions = {
  zoom: 15,
  center: myLatlng
}
var map = new google.maps.Map(document.getElementById("map"), mapOptions);

var marker = new google.maps.Marker({
    position: myLatlng,
    title:productdata.title
});

// To add the marker to the map, call setMap();
marker.setMap(map);
            
            
            
            }
              $('#contact').html('<p>'+address+'</p>');
                  var     social2='';  var   datafacebook='';
                 if(productdata.plugins[0].facebook!='')
                 { 
                       if(productdata.plugins[0].facebook.indexOf("facebook")!=-1)
                        {
                            datafacebook=productdata.plugins[0].facebook;
                        if(productdata.plugins[0].facebook.indexOf("http")==-1)
                        {
                            datafacebook="http://"+productdata.plugins[0].facebook;

                        }
                                            
                        social2 += '<li><a href="'+datafacebook+'"><img width="29" height="29" alt="Facebook" src="/imglevel/shop/icon-social-01.png"></a></li>';
                        }
                        
                        if(productdata.plugins[0].website=='')
                        {
                        
                        $('#btnfav').attr('href',datafacebook);
                        
                        $('#btnfav').attr('target',"_blank");
                        
                        }
                        
                        
                        
                 }
                 if(productdata.plugins[0].twitter!='')
                 {
                 
                        if(productdata.plugins[0].twitter.indexOf("twitter")!=-1)
                        {
                         datafacebook=productdata.plugins[0].twitter;
                        if(productdata.plugins[0].twitter.indexOf("http")==-1)
                        {
                            datafacebook="http://"+productdata.plugins[0].twitter;

                        }
                                            
                        social2 += '<li><a href="'+datafacebook+'"><img width="29" height="29" alt="Twitter" src="/imglevel/shop/icon-social-02.png"></a></li>';
                        }
                 
                 
                 }
                 if(productdata.plugins[0].googleplus!='')
                 {
                 
                 
                          if(productdata.plugins[0].googleplus.indexOf("plus.google")!=-1)
                        {
                           datafacebook=productdata.plugins[0].googleplus;
                        if(productdata.plugins[0].googleplus.indexOf("http")==-1)
                        {
                            datafacebook="http://"+productdata.plugins[0].googleplus;

                        }
                                            
                        social2+= '<li><a href="'+datafacebook+'"><img width="29" height="29" alt="Google +" src="/imglevel/shop/icon-social-06.png"></a></li>';
                        }
                 
                 
                 }
                 if(productdata.plugins[0].email!='')
                 {
                 
                      
                            datafacebook="mailto:"+productdata.plugins[0].email;

                        
                                            
                        social2+= '<li><a href="'+datafacebook+'"><img width="29" height="29" alt="Email" src="/imglevel/shop/icon-social-07.png"></a></li>';
                        
                 
                 }
                 $('#social2').html(social2);
                 if(productdata.plugins[0].arrayimage.length)
                 {
                 $.each(productdata.plugins[0].arrayimage, function( index, value ) {
                 //alert( index + ": " + value );
                 
                                         $('.d-'+value.width+'x'+value.height+'').eq(parseInt(value.index,10)).append('<img src="'+value.simg.newpath+'">')
                 
                 
                 });
                 
                 
                 }
                 
                 if(productdata.plugins[0].url!='')
                 {
                 
                              $('#clip').html('<iframe width="446" height="300" frameborder="0" allowfullscreen="" src="'+productdata.plugins[0].url+'?wmode=transparent"></iframe>');
                 
                 
                 }
                 
                  if($('a.button.black2').length)
                  {

                         $('a.button.black2').hide();
                  
                  
                  }
                  
                  $('#btnfav').html('Website');
                  $('#btnfriend').html('Share');
                  $('#btnfriend').attr('onclick','sharefunction(0,'+productidset+',\'\')');
                  
                  
                 if(getCookie('userid')==productdata.createby) 
                 {
                 seteventimage(220,90);
                 seteventimage(676,316);
                 seteventimage(220,160);
                 seteventimage(208,148);
                 seteventimage(940,370);
                 seteventimage(940,350);
                 seteventimage(940,400);
                 seteventimage(100,110);
                 seteventimage(460,309);
                 seteventimage(940,310);
                 seteventimage(306,550);
                 seteventimage(460,477);
                 seteventimage(940,360);
                 seteventimage(940,440);
                 seteventimage(676,316);
                 seteventimage(460,260);
                 seteventimage(676,402);

                 
                 }
});        





});